package leetcode_1801_1900;

public class LeeCode_1806 {
    public static void main(String[] args) {
        System.out.println(reinitializePermutation(6));
    }
    private static int reinitializePermutation(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = i;
        }
        int count = 0;
        int[] tmp = new int[n];
        while (count == 0 || !check(arr)){
            for (int i = 0; i < n; i++) {
                if ((i & 1) == 1){
                    tmp[i] = arr[n / 2 + (i - 1) / 2];
                }else {
                    tmp[i] = arr[i / 2];
                }
            }
            arr = tmp;
            tmp = new int[n];
            count++;
        }
        return count;
    }
    private static boolean check(int[] arr){
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            if (arr[i] != i)
                return false;
        }
        return true;
    }
}
